﻿using System;
using System.Web;
using System.Web.Mvc;
using Service.Infrastructure.Implement;
using Web.Controllers;


namespace Web.Filter
{
    [AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
    public class ManagerFilter : BaseFilter, IActionFilter
    {
        private const String LoginUrl = "~/Sys/Login";

        public void OnActionExecuted(ActionExecutedContext filterContext)
        {

        }

        /// <summary>
        ///     Action访问前调用，检查Userid是否为空，为空未登录
        /// </summary>
        /// <param name="filterContext"></param>
        public void OnActionExecuting(ActionExecutingContext filterContext)
        {

            Init(filterContext);
            LoggingVist();
            /*
            if (filterContext.ActionParameters.Count == 0)//传递参数为0，非操作Action
                return;
            */

            if (HttpContext.Current.Session[Base.ManagerSessionKey] == null)
            {
                //string ReferrerUrl = filterContext.RequestContext.HttpContext.Request.UrlReferrer.AbsoluteUri;
                filterContext.Result = new RedirectResult(LoginUrl);
                //filterContext.Controller.TempData[Base.ErrorInfo] = MessageResources.AccountSessionIsLost;
            }
            /*
            Results result = service.oerationAuthorityVerification(userid, controllerName, actionName);
             */

        }
    }
}
